<template>
	<view>
		<view class="login-logo">
			<u-image width="200rpx" height="200rpx" :src="logo"></u-image>
		</view>
		<view class="" style="padding: 0 30rpx;">
			<u-form :model="data" ref="uForm">
				<u-form-item v-for="(item,index) in inputs" :key="index">
					<view class="u-flex" style="height: 100rpx;flex:1">
						<u-input :prefix-icon="item.icon" v-model="data[item.value]" :placeholder="item.placeholder"
							:type="item.type" />
					</view>
				</u-form-item>
			</u-form>
			<view style="height: 60rpx;">

			</view>
			<u-button type="primary" :disabled="btndisabled" :loading="loading"
				@click="login">{{$z.$t("登录")}}</u-button>
			<view class="u-flex operate u-row-between">
				<view class="register" @click="registerfn">
					{{$z.$t("注册")}}
				</view>
				<view @click="forgetPassword">
					{{$z.$t("忘记密码")}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import request from "@/z/function/request";
	import logo from "@/static/logo.png"
	export default {
		data() {
			return {
				logo,
				loading: false,
				data: {
					uUser: "",
					dma: "",
				},
				inputs: [{
					value: "uUser",
					placeholder: this.$z.$t("用户名"),
					icon: 'account'
				}, {
					value: "dma",
					type: "password",
					placeholder: this.$z.$t("密码"),
					icon: 'lock'
				}]
			}
		},
		computed: {
			btndisabled() {
				for (let i in this.data) {
					if (this.data[i] == "") {
						return true
					}
				}
				return false
			}
		},
		onLoad() {
			console.log('登录页面');
		},
		methods: {
			registerfn() {
				uni.navigateTo({
					url: "/pages/register/register"
				})
			},
			forgetPassword() {
				uni.navigateTo({
					url: "/pages/forgetPassword/forgetPassword"
				})
			},
			async login() {
				this.loading = true;
				console.log('1111')
				try {
					const [res] = await request("/Login", this.data);

					if (res.par === 'succeed') {
						const [info] = await uni.$z.request("/GetSession")
						uni.setStorageSync('utype', info.utype)
						if (info.utype == 0 || info.utype == 106 || info.utype == 5 || info.utype == 6) {
							if (uni.getStorageSync('utype') == 0) {
								uni.reLaunch({
									url: "/pages/index2/index2"
								})
							} else {
								uni.reLaunch({
									url: "/pages/index1/index1"
								})
							}

						} else {
							uni.showToast({
								title: this.$z.$t("系统暂不支持"),
								icon: 'error'
							})
						}

					} else {
						uni.showToast({
							title: this.$z.$t("登录失败"),
							icon: 'error'
						})
					}
					// uni.$z.$cookie.setCookie("user", data);
					// uni.reLaunch({
					// 	url: "/pages/index/index"
					// })
					this.loading = false;
				} catch (e) {
					//TODO handle the exception
					this.loading = false;
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.operate {
		margin-top: 10px;
		height: 60rpx;
		color: #2093f5;

	}

	.register {
		margin-right: 30px
	}

	.login-logo {
		display: flex;
		justify-content: center;
		padding-top: 200rpx;
	}

	.u-input--radius,
	.u-input--square[data-v-113bc24f] {
		border-radius: 19px;
	}
</style>